package com.dc.project.basics.controller;

import com.dc.common.validated.InsertGroup;
import com.dc.common.validated.QueryPageGroup;
import com.dc.common.validated.UpdateGroup;
import com.dc.common.vo.ResultVo;
import com.dc.project.basics.dto.BasProductDto;
import com.dc.project.basics.entity.BasProduct;
import com.dc.project.basics.service.BasProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * 产品表(BasProduct)表控制层
 *
 * @author zhuangcy
 * @since 2021-06-11 14:40:02
 */
@RestController
@RequestMapping("basProduct")
@Api(tags = "产品表")
public class BasProductController {
    /**
     * 服务对象
     */
    @Autowired
    private BasProductService basProductService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return
     */
    @GetMapping("{id}")
    @ApiOperation("通过主键查询单条数据")
    @RequiresPermissions("basics:basProduct:query")
    public ResultVo get(@PathVariable Serializable id) {
        return this.basProductService.queryById(id);
    }

    /**
     * 分页查询产品表
     *
     * @param dto
     * @return
     */
    @GetMapping
    @ApiOperation("分页查询产品表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", defaultValue = "10", required = true)
    })
    @RequiresPermissions("basics:basProduct:query")
    public ResultVo listPage(@Validated(QueryPageGroup.class) BasProductDto dto) {
        return this.basProductService.queryByPage(dto);
    }

    /**
     * 新增产品表
     *
     * @param basProduct
     * @return
     */
    @PostMapping
    @ApiOperation("新增产品表")
    @RequiresPermissions("basics:basProduct:add")
    public ResultVo add(@Validated(value = {InsertGroup.class}) @RequestBody BasProduct basProduct) {
        return this.basProductService.add(basProduct);
    }

    /**
     * 编辑产品表
     *
     * @param basProduct
     * @return
     */
    @PutMapping
    @ApiOperation("编辑产品表")
    @RequiresPermissions("basics:basProduct:edit")
    public ResultVo edit(@Validated(value = {UpdateGroup.class}) @RequestBody BasProduct basProduct) {
        return this.basProductService.edit(basProduct);
    }

    /**
     * 根据主键删除产品表
     *
     * @param id 主键
     * @return
     */
    @DeleteMapping("{id}")
    @ApiOperation("根据主键删除产品表")
    @RequiresPermissions("basics:basProduct:delete")
    public ResultVo delete(@PathVariable Serializable id) {
        return this.basProductService.delete(id);
    }

}